package flc.ast.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.cartoonavatarmaker.lib.core.AvatarRole;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class RoleAdapter extends StkProviderMultiAdapter<AvatarRole> {

    public RoleAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(45));
        addItemProvider(new RoleProvider());
    }

    private class RoleProvider extends BaseItemProvider<AvatarRole> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_role;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, AvatarRole bean) {
            if (baseViewHolder.getAdapterPosition() == 0) {
                baseViewHolder.setImageResource(R.id.ivRoleItemImg, R.drawable.kp_xj);
            } else {
                Glide.with(baseViewHolder.itemView).load(bean.imgUri).into((ImageView) baseViewHolder.getView(R.id.ivRoleItemImg));
            }
            baseViewHolder.setText(R.id.tvRoleItemName, bean.name);
            if (bean.isSelected()) {
                baseViewHolder.getView(R.id.ivRoleItemSel).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.ivRoleItemSel).setVisibility(View.GONE);
            }
        }
    }
}
